package com.apobates.jforum.grief.aurl.selector;

import com.apobates.jforum.grief.aurl.core.AUrlMeta;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.function.Supplier;

/**
 * AUrlMeta常规部分取值
 */
public abstract class AUrlMetaGeneralSelector extends AUrlMetaSelector<Collection<String>>{
    public AUrlMetaGeneralSelector(AUrlMeta rawMeta) {
        super(rawMeta);
    }

    protected static Supplier<Collection<String>> EMPTY = ()-> Collections.emptyList();

    /**
     * 从查询器中选择单个值
     * @param defaultVal 默认值
     * @return
     */
    public String getSingle(Supplier<String> defaultVal){
        Collection<String> result = getResult();
        if(result.isEmpty()){
            return defaultVal.get();
        }
        return new ArrayList<>(result).get(0);
    }
}
